$(function(){
	var host="weixin.yiyikefu.com/index.php";

	$('#btnlogin').click(function(){
		var email = $('.r_email') .val();
		var psw = $('.r_psw').val();
		var openid = $('.openid').val();

		if(email != "" && psw != "" && openid !=""){
			$.ajax({
	            type: 'POST',
	            url: 'http://'+host+'?s=/Weixin/User/login_json',
	            
	            dataType: 'jsonp',  //类型
	            data: {email:email,password:psw,openid:openid},
	            jsonp: 'callback', //jsonp回调参数，必需
	            async: false,
	            success: function(result) {//返回的json数据
	            	if(result.success){
	            		if(result.content.indexOf("http://",0)>=0){
							  window.location.href = result.content;
						}else{
							  window.location.href = result.content;
						}
	            	}else{
						if(result.code=='-1'){
							popMsg('(⊙o⊙)…帐号不存在或密码错误，请重新填写');
							return false;
						}else if(result.code=='-2'){
							popMsg('账号绑定失败,请进入依医微信服务号进行账号绑定！');
							return false;
						}
						$('.err_email').html('<em>!</em>无效邮箱').show(100);
						return false;
					}
	            },
	            timeout: 3000
	        });
		}
		return false;
	});

	function popMsg(msg){
		$('body').append('<div id="popLayer">'+msg+'</div>');
		$('#popLayer').addClass('pop');
		setTimeout(function(){$('#popLayer').removeClass('pop')},3000);
	}
	
	//valid funcitons
	function checkEmail(email){
		var reg = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
		if(!reg.test($.trim(email))){
			return false;
		}else{
			return true;
		}
	}

	function checkPsw(psw){
		var len = $.trim(psw).length;
		if(len<6 || len > 16){
			return false;
		}else{
			return true;
		}
	}

	function checkName(name){
		var len = name.length;
		if(len<1 || len > 20){
			return false;
		}else{
			return true;
		}
	}
});
